package com.zhang.controller;

import com.zhang.entity.response.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * User: 张
 * Date: 2024-11-13
 * Time: 16:12
 * Description:
 */
@RestController
@RequestMapping("/monitor")
public class MonitorController {
    @Autowired
    private DiscoveryClient discoveryClient;

    @RequestMapping("/hello")
    public ResponseResult<Object> hello(){
        for (String service : discoveryClient.getServices()) {
            discoveryClient.getInstances(service).forEach(instance -> System.out.println(instance.getHost()+":"+instance.getPort()+" "+instance.getUri()));
        }
        return ResponseResult.success("Device Service \n" + discoveryClient.getServices().toString());
    }



}
